package controller

import (
	"gicechina/help"
	"html/template"
	"net/http"
	"strconv"
)

type Category struct{}

//关于我们
func (c *Category) About(write http.ResponseWriter, r *http.Request) {
	cateInfo, _ := CategoryModel.GetInfoById(1)
	TemplateData["cateInfo"] = cateInfo
	TemplateData["indexCurrent"] = ""
	TemplateData["aboutCurrent"] = "current"
	TemplateData["activeCurrent"] = ""
	TemplateData["projectCurrent"] = ""
	TemplateData["videoCurrent"] = ""
	TemplateData["newsCurrent"] = ""
	TemplateData["contactCurrent"] = ""
	TemplateData["aboutClass"] = "current"
	TemplateData["cultureClass"] = ""
	TemplateData["advantageClass"] = ""
	TemplateData["jobCurrent"] = ""
	var con template.HTML
	con = template.HTML(cateInfo.Content)
	TemplateData["Content"] = con
	getGiceReport()
	getGiceActive()
	help.ParseTemplate(write, "about.html", &TemplateData, "layout", "about", "header", "footer", "right")
}

//优势
func (c *Category) Advantage(write http.ResponseWriter, r *http.Request) {
	cateInfo, _ := CategoryModel.GetInfoById(8)
	TemplateData["cateInfo"] = cateInfo
	TemplateData["indexCurrent"] = ""
	TemplateData["aboutCurrent"] = "current"
	TemplateData["activeCurrent"] = ""
	TemplateData["projectCurrent"] = ""
	TemplateData["videoCurrent"] = ""
	TemplateData["newsCurrent"] = ""
	TemplateData["contactCurrent"] = ""
	TemplateData["aboutClass"] = ""
	TemplateData["cultureClass"] = ""
	TemplateData["advantageClass"] = "current"
	TemplateData["jobCurrent"] = ""
	var con template.HTML
	con = template.HTML(cateInfo.Content)
	TemplateData["Content"] = con
	getGiceReport()
	getGiceActive()
	help.ParseTemplate(write, "about.html", &TemplateData, "layout", "about", "header", "footer", "right")
}

//文化
func (c *Category) Culture(write http.ResponseWriter, r *http.Request) {
	cateInfo, _ := CategoryModel.GetInfoById(7)
	TemplateData["cateInfo"] = cateInfo
	TemplateData["indexCurrent"] = ""
	TemplateData["aboutCurrent"] = "current"
	TemplateData["activeCurrent"] = ""
	TemplateData["projectCurrent"] = ""
	TemplateData["videoCurrent"] = ""
	TemplateData["newsCurrent"] = ""
	TemplateData["contactCurrent"] = ""
	TemplateData["aboutClass"] = ""
	TemplateData["cultureClass"] = "current"
	TemplateData["jobCurrent"] = ""
	TemplateData["advantageClass"] = ""
	var con template.HTML
	con = template.HTML(cateInfo.Content)
	TemplateData["Content"] = con
	getGiceReport()
	getGiceActive()
	help.ParseTemplate(write, "about.html", &TemplateData, "layout", "about", "header", "footer", "right")
}

//GICE活动
func (c *Category) Active(write http.ResponseWriter, r *http.Request) {
	cateInfo, _ := CategoryModel.GetInfoById(2)
	TemplateData["cateInfo"] = cateInfo
	page := r.FormValue("page")
	pageInt := 1
	if page != "" {
		pageInt, _ = strconv.Atoi(page)
		if pageInt <= 0 {
			pageInt = 1
		}
	}
	//分页获取全部的活动
	params := make(map[string]interface{})
	params["status"] = "2"
	params["category_id"] = "2"
	params["order"] = "update_time desc"
	total := ActiveModel.Count(params)
	if pageInt > total {
		pageInt = total
	}
	start := (pageInt - 1) * 10
	params["limit"] = strconv.Itoa(start) + ",10"
	list := ActiveModel.Item(params)
	res := help.Page(pageInt, 10, total)
	TemplateData["page"] = res
	TemplateData["list"] = list
	TemplateData["indexCurrent"] = ""
	TemplateData["aboutCurrent"] = ""
	TemplateData["activeCurrent"] = "current"
	TemplateData["projectCurrent"] = ""
	TemplateData["videoCurrent"] = ""
	TemplateData["newsCurrent"] = ""
	TemplateData["contactCurrent"] = ""
	TemplateData["jobCurrent"] = ""
	getGiceReport()
	getGiceActive()
	help.ParseTemplate(write, "active.html", &TemplateData, "layout", "active", "header", "footer", "right")
}

//联系我们
func (c *Category) Contact(write http.ResponseWriter, r *http.Request) {
	cateInfo, _ := CategoryModel.GetInfoById(6)
	TemplateData["cateInfo"] = cateInfo
	TemplateData["indexCurrent"] = ""
	TemplateData["aboutCurrent"] = ""
	TemplateData["activeCurrent"] = ""
	TemplateData["projectCurrent"] = ""
	TemplateData["videoCurrent"] = ""
	TemplateData["newsCurrent"] = ""
	TemplateData["jobCurrent"] = ""
	TemplateData["contactCurrent"] = "current"
	var con template.HTML
	con = template.HTML(cateInfo.Content)
	TemplateData["Content"] = con
	getGiceReport()
	getGiceActive()
	help.ParseTemplate(write, "contact.html", &TemplateData, "layout", "contact", "header", "footer", "right")
}

//新闻列表
func (c *Category) News(write http.ResponseWriter, r *http.Request) {
	getList(5, r)
	TemplateData["indexCurrent"] = ""
	TemplateData["aboutCurrent"] = ""
	TemplateData["activeCurrent"] = ""
	TemplateData["projectCurrent"] = ""
	TemplateData["videoCurrent"] = ""
	TemplateData["newsCurrent"] = "current"
	TemplateData["contactCurrent"] = ""
	TemplateData["jobCurrent"] = ""
	getGiceReport()
	getGiceActive()
	help.ParseTemplate(write, "news.html", &TemplateData, "layout", "news", "header", "footer", "right")
}

//在线视频
func (c *Category) Video(write http.ResponseWriter, r *http.Request) {
	getList(4, r)
	TemplateData["indexCurrent"] = ""
	TemplateData["aboutCurrent"] = ""
	TemplateData["activeCurrent"] = ""
	TemplateData["projectCurrent"] = ""
	TemplateData["videoCurrent"] = "current"
	TemplateData["newsCurrent"] = ""
	TemplateData["contactCurrent"] = ""
	TemplateData["jobCurrent"] = ""
	getGiceReport()
	getGiceActive()
	help.ParseTemplate(write, "video.html", &TemplateData, "layout", "video", "header", "footer", "right")
}

//GICE项目
func (c *Category) Project(write http.ResponseWriter, r *http.Request) {
	getList(3, r)
	TemplateData["indexCurrent"] = ""
	TemplateData["aboutCurrent"] = ""
	TemplateData["activeCurrent"] = ""
	TemplateData["projectCurrent"] = "current"
	TemplateData["videoCurrent"] = ""
	TemplateData["newsCurrent"] = ""
	TemplateData["contactCurrent"] = ""
	TemplateData["jobCurrent"] = ""
	getGiceReport()
	getGiceActive()
	help.ParseTemplate(write, "project.html", &TemplateData, "layout", "project", "header", "footer", "right")
}

//加入gice
func (c *Category) Job(write http.ResponseWriter, r *http.Request) {
	getList(9, r)
	TemplateData["indexCurrent"] = ""
	TemplateData["aboutCurrent"] = ""
	TemplateData["activeCurrent"] = ""
	TemplateData["projectCurrent"] = ""
	TemplateData["videoCurrent"] = ""
	TemplateData["newsCurrent"] = ""
	TemplateData["contactCurrent"] = ""
	TemplateData["jobCurrent"] = "current"
	getGiceReport()
	getGiceActive()
	help.ParseTemplate(write, "job.html", &TemplateData, "layout", "job", "header", "footer", "right")
}

//在线课堂
func (c *Category) OnlineCourse(write http.ResponseWriter, r *http.Request) {
	getList(9, r)
	TemplateData["indexCurrent"] = ""
	TemplateData["aboutCurrent"] = ""
	TemplateData["activeCurrent"] = ""
	TemplateData["projectCurrent"] = ""
	TemplateData["videoCurrent"] = ""
	TemplateData["newsCurrent"] = ""
	TemplateData["contactCurrent"] = ""
	TemplateData["jobCurrent"] = "current"
	getGiceReport()
	getGiceActive()
	help.ParseTemplate(write, "job.html", &TemplateData, "layout", "job", "header", "footer", "right")
}

//获取数据
func getList(id int, r *http.Request) {
	cateInfo, _ := CategoryModel.GetInfoById(id)
	TemplateData["cateInfo"] = cateInfo
	page := r.FormValue("page")
	pageInt := 1
	if page != "" {
		pageInt, _ = strconv.Atoi(page)
		if pageInt <= 0 {
			pageInt = 1
		}
	}
	//分页获取全部的活动
	params := make(map[string]interface{})
	params["status"] = "2"
	params["category_id"] = "" + strconv.Itoa(id)
	params["order"] = "update_time desc"
	if id == 9 {
		total := JobModel.Count(params)
		if pageInt > total && total != 0{
			pageInt = total
		}
		start := (pageInt - 1) * 10
		params["limit"] = strconv.Itoa(start) + ",10"
		list := JobModel.Item(params)
		res := help.Page(pageInt, 10, total)
		TemplateData["page"] = res
		TemplateData["list"] = list
	} else {
		total := NewsModel.Count(params)
		if pageInt > total && total != 0{
			pageInt = total
		}
		start := (pageInt - 1) * 10
		params["limit"] = strconv.Itoa(start) + ",10"
		list := NewsModel.Item(params)
		res := help.Page(pageInt, 10, total)
		TemplateData["page"] = res
		TemplateData["list"] = list
	}

}
